package cn.lili.controller.promotion;


import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.BlindboxPrizePaper;
import cn.lili.modules.promotion.entity.dto.search.BlindboxPrizepaperSearchParams;
import cn.lili.modules.promotion.entity.vos.BlindboxRuleVO;
import cn.lili.modules.promotion.entity.vos.BlindboxVO;
import cn.lili.modules.promotion.service.BlindboxPrizePaperService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;


/**
 * @author xiangqian
 */
@RestController
@Api(tags = "盲盒奖卷接口")
@RequestMapping("/promotion/blindbox/prizepaper")
@RequiredArgsConstructor
public class BlindboxPrizePaperController {

    private final BlindboxPrizePaperService blindboxPrizePaperService;

    @ApiOperation(value = "获取盲盒奖卷列表")
    @GetMapping
    public ResultMessage<Page<BlindboxPrizePaper>> getPage(BlindboxPrizePaper queryParam, PageVO page) {
        return ResultUtil.data(blindboxPrizePaperService.getPage(queryParam, page));
    }

    @ApiOperation(value = "根据商品id查询盲盒活动")
    @GetMapping("/getBlindbox/{goodsId}")
    public ResultMessage<BlindboxVO> getBlindbox(@PathVariable String goodsId) {
        AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
        return ResultUtil.data(blindboxPrizePaperService.getBlindbox(currentUser, goodsId));
    }

    @ApiOperation(value = "查询我的已读/未读/所有奖卷")
    @GetMapping("/getPrizepaper")
    public ResultMessage<List<BlindboxPrizePaper>> getPrizepaper(BlindboxPrizepaperSearchParams blindboxPrizepaperSearchParams) {
        AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
        return ResultUtil.data(blindboxPrizePaperService.getPrizepaper(currentUser, blindboxPrizepaperSearchParams));
    }

    @ApiOperation(value = "标记为已读奖卷")
    @PutMapping("/updatePrizepaperRead")
    public ResultMessage<Object> updatePrizepaperRead(@RequestBody List<String> codes) {
        AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
        return ResultUtil.data(blindboxPrizePaperService.updatePrizepaperRead(currentUser, codes));
    }
}
